// pages/home/pages/party1ApplyDetail/party1ApplyDetail.js
var r = require('../../../../utils/request.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    disabled:false,

    name: '',
    age:'',
    sex: '',
    sexName: '请选择性别',
    identity: '', //身份证号
    nation: '', //民族
    nationality: '', //籍贯
    household: '', //户籍所在地
    residence: '', //现居住地
    phone: '', //联系方式

    school: '',
    education: '',
    major: '',
    degree: '',
  },

  // 性别
  getSex() {
    if(this.data.disabled){
      return
    }
    var that = this
    wx.showActionSheet({
      itemList: ['男', '女'],
      success: function (res) {
        // console.log(res.tapIndex)
        if (res.tapIndex == 0) {
          that.setData({
            sexName: '男',
            sex: 'M'
          })
        } else {
          that.setData({
            sexName: '女',
            sex: 'F'
          })
        }
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },

  // 获取值
  getval(e) {
    let num = e.currentTarget.dataset.num
    if (num == 0) {
      this.setData({
        name: e.detail.value
      })
    } else if (num == 1) {
      this.setData({
        age: e.detail.value
      })
    } else if (num == 2) {
      this.setData({
        nation: e.detail.value
      })
    } else if (num == 3) {
      this.setData({
        identity: e.detail.value
      })
    } else if (num == 4) {
      this.setData({
        nationality: e.detail.value
      })
    } else if (num == 5) {
      this.setData({
        household: e.detail.value
      })
    } else if (num == 6) {
      this.setData({
        residence: e.detail.value
      })
    } else if (num == 7) {
      this.setData({
        phone: e.detail.value
      })
    } else if (num == 8) {
      this.setData({
        school: e.detail.value
      })
    } else if (num == 9) {
      this.setData({
        education: e.detail.value
      })
    } else if (num == 10) {
      this.setData({
        major: e.detail.value
      })
    } else if (num == 11) {
      this.setData({
        degree: e.detail.value
      })
    }
  },

  submit(){
    let param = {
      applyName: this.data.name,
      applyAge:this.data.age,
      applySex: this.data.sex,
      applyIdcard: this.data.identity, //身份证号
      applyNation: this.data.nation, //民族
      applyNative:this.data.nationality, //籍贯
      applyAddress: this.data.household, //户籍所在地
      applyPlace: this.data.residence, //现居住地
      applyPhone: this.data.phone, //联系方式
      applySchool: this.data.school,
      applyEducation: this.data.education,
      applyMajor: this.data.major,
      applyAcademic:this.data.degree
    }
    r.toPost('/dwPartyApply/applyAdd', param, (res) => {
      wx.showToast({
        title: '操作成功',
        icon:'none'
      })
      setTimeout(function(){
        wx.navigateBack({
          delta: 1,
        })
      },800)
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})